package android_serialport_api;

import android.util.Log;

import java.io.File;
import java.util.Vector;

public class SerialPortFinderDriver {
    private String mDriverName;
    private String mDeviceRoot;
    Vector<File> mDevices;

    public SerialPortFinderDriver(SerialPortFinder this$0, String name, String root) {
//        this.this$0 = this$0;
        this.mDevices = null;
        this.mDriverName = name;
        this.mDeviceRoot = root;
    }

    public Vector<File> getDevices() {
        if (this.mDevices == null) {
            this.mDevices = new Vector();
            File dev = new File("/dev");
            File[] files = dev.listFiles();

            for(int i = 0; i < files.length; ++i) {
                if (files[i].getAbsolutePath().startsWith(this.mDeviceRoot)) {
                    Log.d("SerialPort", "Found new device: " + files[i]);
                    this.mDevices.add(files[i]);
                }
            }
        }

        return this.mDevices;
    }

    public String getName() {
        return this.mDriverName;
    }
}
